#include <iostream>
#include <cstdlib>

int main()
{
    // int *a = (int *)malloc(sizeof(int));
    // if(a == NULL)
    // {
    //     return -1;
    // }
    // *a = 10;
    // std::cout<<*a<<std::endl;
    // free(a);

    //new delete : 关键字
    // int *a = (int *)malloc(sizeof(int));
    //1、不需要计算内存大小
    //2、不需要转换指针
    //3、不需要判断返回值是否为空 : c++一旦申请空间失败，抛出内存异常
    //4、小括号直接初始化内存值
    // int *a = new int;
    // *a = 10;
    // std::cout<<*a<<std::endl;
    // delete a;  //释放指针


    //一维数组
    // int *a = new int(3);
    // delete []a; //释放数组


    //二维数组
    int **a = new int*[2];
    for(int i = 0; i < 2; i++)
        a[i] = new int[3];

    for(int i = 0; i < 2; i++)
        delete []a[i];
    delete []a;
    
    return 0;
}